package com.haidechizi.leetcode;

import java.sql.Struct;

/**
 * @author: wangdejun
 * @create: 2020-04-02 12:17
 **/
public class _16_数值的整数次方 {

    public double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return x;
        }
        boolean isNegative = false;
        if (n < 0) {
            isNegative = true;
            n = -n;
        }
        double result = myPow(x * x, n / 2);
        if (n % 2 == 1) {
            result *= x;
        }
        return isNegative ? 1 / result : result;

    }
}
